package project.Service.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import project.Dto.QuestionDto;
import project.Mapper.BasicQuestionMapper;
import project.Mapper.MentalQuestionMapper;
import project.Pojo.BasicQuestion;
import project.Pojo.MentalQuestion;
import project.Service.QuestionService;

import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class QuestionServiceImpl implements QuestionService {

    @Autowired
    BasicQuestionMapper basicQuestionMapper;

    @Autowired
    MentalQuestionMapper mentalQuestionMapper;

    @Override
    public List<QuestionDto> createQuestionnaire() {
//        List<BasicQuestion> basicQuestions = basicQuestionMapper.selectAllbq();
        List<MentalQuestion> mentalQuestions = mentalQuestionMapper.selectAllmq();

        Collections.shuffle(mentalQuestions, new SecureRandom());
        List<MentalQuestion> mentalrandom25 = mentalQuestions.subList(0, Math.min(25, mentalQuestions.size()));

        List<QuestionDto> result = new ArrayList<>();
//        for (BasicQuestion basicQuestion : basicQuestions) {
//            QuestionDto questionDto = new QuestionDto();
//            questionDto.setQId(basicQuestion.getBqId());
//            questionDto.setQuestion(basicQuestion.getBqQuestion());
//            result.add(questionDto);
//        }
        for (MentalQuestion mentalQuestion : mentalrandom25) {
            QuestionDto questionDto = new QuestionDto();
            questionDto.setQId(mentalQuestion.getMqId());
            questionDto.setQuestion(mentalQuestion.getMqQuestion());
            result.add(questionDto);
        }
        return result;
    }
}
